package main

import (
	"fmt"
	"time"
	"runtime"
)

func main() {
	ch := make(chan int)
	flag := make(chan bool)
	go func() {
		for i := 0; i < 5; i++ {
			ch <- i
			time.Sleep(time.Second)
		}
		close(ch)
		flag <- true

	}()


	for {
		select {
		case mun := <-ch:
			fmt.Println(mun)

		case <-flag:
			//break//只跳出了case
			return//main结束

		}
	}

	runtime.Goexit()
}
